# Maintainer: Noel Kuntze <noel.kuntze@contauro.com>
pkgname=grommunio-admin-api
pkgdesc="Backend for grommunio management"
pkgver=1.14
pkgrel=0
arch="noarch !riscv64"
url="http://www.grommunio.com"
license="AGPL-3.0-only"
options="!check" # No test suite
subpackages="$pkgname-doc $pkgname-openrc $pkgname-bash-completion"
makedepends="cmake py3-yaml ninja nginx"
depends="grommunio-admin-common
	grommunio-gromox
	libexmdbpp
	py3-ldap3
	py3-mysqlclient
	py3-redis
	py3-sqlalchemy
	py3-argcomplete
	py3-jsonschema
	py3-idna
	py3-dnspython
	py3-cryptography
	py3-psutil
	py3-yaml
	py3-flask
	py3-jwt
	py3-multidict
	py3-openapi-codec
	py3-requests
	uwsgi
	"

pkgusers="grommunio"
pkggroups="grommunio"

source="$pkgname-$pkgver.tar.gz::https://github.com/grommunio/admin-api/archive/refs/tags/$pkgver.tar.gz
	0001-makefile.patch
	grommunio-admin-api.initd
	grommunio-admin-api.confd
	database.yaml
	"

builddir="$srcdir/admin-api-$pkgver"

build() {
	cmake -B build -G Ninja \
		-DCMAKE_INSTALL_PREFIX=/usr \
		-DCMAKE_INSTALL_LIBDIR=lib \
		-DCONFDIR=/usr/share/examples/grommunio-admin-api \
		-DCOMMONCONFDIR=/usr/share/examples/grommunio-admin-common \
		-DCMAKE_BUILD_TYPE=MinSizeRel

	cmake --build build
}

package() {
	DESTDIR="$pkgdir" cmake --install build

	# create first dummy service to get the directory and overwrite it with symlink to uwsgi
	install -m755 -D "$srcdir"/$pkgname.initd "$pkgdir"/etc/init.d/$pkgname
	ln -sf "/etc/init.d/uwsgi" "$pkgdir/etc/init.d/$pkgname"
	install -m644 -D "$srcdir"/$pkgname.confd "$pkgdir"/etc/conf.d/$pkgname
	install -m644 -D "$srcdir"/database.yaml "$pkgdir"/etc/grommunio-admin-api/conf.d/database.yaml
	install -d -m0775 -o grommunio -g nginx "$pkgdir"/var/run/grommunio
}

sha512sums="
3dfb6a0c194d862f0358dd854830b52f84730b8944940aa5a3ec200f50a3a5cef03184347684a08978b146ed0214d969962ac8d299b68f146551b3be3446f693  grommunio-admin-api-1.14.tar.gz
47dc0698ca3d107b9a37f4778c386d099bd24bfaa6104e9512166b0266898dfcb1a63eb1eb2b1bb27d7d54b56560c4cfb6f3a48c7e56e5a61c21cb445aa830ea  0001-makefile.patch
b87910a731ad58b86679b08674632fffb4d76a94ad67602906200acf7e36fb23508ec19f56ca2f8a1e257a7ef3a32c4dbfa7b27d9d902006eff3d92d8816c067  grommunio-admin-api.initd
b634a1d20372f45e9f9e347d9f0b0785dca561849920381e223b2a7f356d7e9a37299087b8b6e69d8caf1af87313f14d8e0ac85699bafd9258c6e7153c590cf5  grommunio-admin-api.confd
bf166f9f46d3a6755c2273502576c63060b17d2eb7a4abbac9da5ed1b74a4ed47baf6269eda58adf04657a78028e862572cd7b24d9c8b5b6497b778338def12f  database.yaml
"
